// Copyright 2025 RisingWave Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::TempoConfig;
pub struct TempoGen;

impl TempoGen {
    pub fn gen_tempo_yml(&self, config: &TempoConfig) -> String {
        let http_listen_address = &config.listen_address;
        let http_listen_port = config.port;

        let otlp_host = &config.listen_address;
        let otlp_port = config.otlp_port;

        let max_bytes_per_trace = config.max_bytes_per_trace;

        format!(
            r#"# --- THIS FILE IS AUTO GENERATED BY RISEDEV ---
server:
  http_listen_address: "{http_listen_address}"
  http_listen_port: {http_listen_port}
  grpc_server_max_recv_msg_size: 104857600 # 100 Mb
  grpc_server_max_send_msg_size: 104857600 # 100 Mb

distributor:
  receivers:
      otlp:
        protocols:
          grpc:
            endpoint: "{otlp_host}:{otlp_port}"

# Overrides configuration block
overrides:

  # Global ingestion limits configurations
  defaults:

    # Global enforced overrides
    global:
      # Maximum size of a single trace in bytes.  A value of 0 disables the size
      # check.
      # This limit is used in 3 places:
      #  - During search, traces will be skipped when they exceed this threshold.
      #  - During ingestion, traces that exceed this threshold will be refused.
      #  - During compaction, traces that exceed this threshold will be partially dropped.
      # During ingestion, exceeding the threshold results in errors like
      #    TRACE_TOO_LARGE: max size of trace (5000000) exceeded while adding 387 bytes
      max_bytes_per_trace: {max_bytes_per_trace}
"#
        )
    }
}
